import { updateData } from '@/api/system/dict/data';

export default (await import('vue')).defineComponent({
components: { VideoPlayer },
data() {
return {
faceData: [],
form: {
queryObj: {},
keyWords: '',
pageVo: {
pageSize: 10,
currentPage: 1,
totalDocs: 1
},
searchFields: [
''
],
highLightFields: [
''
],
indexName: '',
typeName: '',
startTime: '',
endTime: ''
},
text: '',
onlineUser: [],
messageList: [],
socket: '',
baseUrl: "http://10.113.16.227:19111/websocket/badao",
//人脸抓拍
captureImgages: [],
//人脸比对
personInfos: [],
alarmList: [],
total: ''
};
},
computed: {
this: .updateData()
},
created() {
this.res();
this.getList();

},
mounted() {
//打开webSocket连接
this.onOpen();
// this.startTimer();
},
methods: {
// startTimer() {
//   // 每5秒更新一次当前时间和获取数据
//   this.timer = setInterval(() => {
//     this.res(); // 更新当前时间
//     this.getList();  // 获取数据
//   }, 3000);
// },
res() {
this.form.flag = 1;
captureData(this.form).then(res => {
this.faceData = [];
this.total = res.data.total;
this.faceData = res.data.list;
});
},
getList() {
listAlarm().then(response => {
this.alarmList = [];
this.alarmList = response.rows;
this.total = response.total;
});
},
playVideo() {
this.$refs.videoPlayer.startPlay();
},
// 连接socket
onOpen: function () {
if (typeof WebSocket == 'undefined') {
console.log('你的浏览器不支持webSocket');
return;
}
const url = this.baseUrl;

this.socket = new WebSocket(url);

this.socket.onopen = () => {
console.log('websocket打开了,用户1连接成功');
};
this.socket.onmessage = (data) => {
updateData();
{
if (!this.isUpdating) { // 检查是否已经在更新中
this.isUpdating = true; // 设置为更新中
this.res();
this.getList();

setTimeout(() => {
this.isUpdating = false; // 重置标志位
this.updateData(); // 30秒后再次尝试更新
}, 30000); // 30秒
}
}
// this.res();
// this.getList();
// alert(data)
// var message = JSON.parse(data.data)
// //判断captureImgages长度，只保留最新的十个
// if (this.captureImgages.length > 10) {
//
//   this.captureImgages.shift()
// }
// // 判断是否为人脸比对
// if (message.isMatch == 1) {
//   this.personInfos.push(message)
// } else {
//   this.captureImgages.push(message);
// }
};
this.socket.onclose = function () {
console.log('断开连接成功');
};
this.playVideo();
}
},
beforeDestroy() {
this.socket.close(); // 关闭socket
}
});
